package com.ktjy.controller;


import com.ktjy.pojo.TbRulePool;
import com.ktjy.service.ITbRulePoolService;
import com.ktjy.utils.AjaxResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 线索池规则 前端控制器
 * </p>
 *
 * @author jjx
 * @since 2025-08-19
 */
@RestController
@Slf4j
@Tag(name="规则管理")
@RequestMapping("/api/tb/rule")
public class TbRulePoolController {
    @Autowired
    private ITbRulePoolService rulePoolService;

    @Operation(summary = "线索/商机规则管理-根据类型查询")
    @GetMapping("/getInfo/{type}")
    public AjaxResult getInfo(@PathVariable("type") String type) {
        TbRulePool rulePool = rulePoolService.findRulePool(type);
        return AjaxResult.success(rulePool);
    }

    @Operation(summary = "线索/商机规则管理-新增")
    @PostMapping("/save")
    public AjaxResult save(@RequestBody TbRulePool rulePool) {
        try {
            boolean ok=rulePoolService.save(rulePool);
            if(ok){
                return AjaxResult.success("保存成功");
            }
        } catch (Exception e) {
            log.error("TbRulePoolController中save方法执行报错的。",e);
        }
        return AjaxResult.error("保存失败");

    }

    @Operation(summary = "线索/商机规则管理-修改")
    @PostMapping("/update")
    public AjaxResult update(@RequestBody TbRulePool rulePool) {
        try {
            boolean ok=rulePoolService.updateById(rulePool);
            if(ok){
                return AjaxResult.success("保存成功");
            }
        } catch (Exception e) {
            log.error("TbRulePoolController中update方法执行报错的。",e);
        }
        return AjaxResult.error("保存失败");
    }
}
